/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.saar.penguin.give2.server.alert;

import de.saar.penguin.give2.server.BigBrother;
import de.saar.penguin.give2.server.Instruction;
import de.saar.penguin.give2.server.SaarNlgSystem;
import give.formula.Position;
import give.world.Room;
import give.world.World;

/**
 *
 * @author koller
 */
public abstract class Alert {
    protected final SaarNlgSystem nlg;
    protected String roomWeGotInitialized;
    protected boolean diesInCreateInstruction = true; //most alerts will be deleted when a new instruction is created
    protected boolean highLevel = false;
    protected boolean finished = false; // we are done with this alert, it can be removed in the next alert list iteration

    protected Alert(SaarNlgSystem nlg) {
        this.nlg = nlg;
        this.roomWeGotInitialized = getCurrentRoom();
    }

    public abstract boolean isActivated(BigBrother bb);

    public abstract Instruction getInstruction();

    public boolean isFinished() {
        return finished;
    }

    protected World w() {
        return nlg.getWorld();
    }

    protected final String getCurrentRoom() {
        Position currentPosition = w().getPlayerPosition();
        Room room = w().getRoomAtPosition(currentPosition.getX(), currentPosition.getZ());
        return room.getName();
    }

    /* TRUE if the player now is in a different room then when the alert got created */
    protected boolean playerJustChangedRooms() {
        return !getCurrentRoom().equals(roomWeGotInitialized);
    }

    public boolean isDiesInCreateInstruction() {
        return diesInCreateInstruction;
    }

    public boolean isHighLevel() {
        return highLevel;
    }

    /*
    public boolean isFinished() {
        return finished;
    }
     * 
     */

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Alert other = (Alert) obj;
        if (this.nlg != other.nlg && (this.nlg == null || !this.nlg.equals(other.nlg))) {
            return false;
        }
        if ((this.roomWeGotInitialized == null) ? (other.roomWeGotInitialized != null) : !this.roomWeGotInitialized.equals(other.roomWeGotInitialized)) {
            return false;
        }
        if (this.diesInCreateInstruction != other.diesInCreateInstruction) {
            return false;
        }
        if (this.highLevel != other.highLevel) {
            return false;
        }
        if (this.finished != other.finished) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 17 * hash + (this.nlg != null ? this.nlg.hashCode() : 0);
        hash = 17 * hash + (this.roomWeGotInitialized != null ? this.roomWeGotInitialized.hashCode() : 0);
        hash = 17 * hash + (this.diesInCreateInstruction ? 1 : 0);
        hash = 17 * hash + (this.highLevel ? 1 : 0);
        hash = 17 * hash + (this.finished ? 1 : 0);
        return hash;
    }

    

    
}
